package com.adamfass.tractorbeam.gameupdatelogic;

import java.util.Set;

import com.adamfass.tractorbeam.Blocker;
import com.adamfass.tractorbeam.GameObjectManager;
import com.adamfass.tractorbeam.GameUpdateLogic;
import com.adamfass.tractorbeam.gameobject.DisruptorField;
import com.jme.util.Timer;

public class DisruptorFieldGameUpdateLogic implements GameUpdateLogic {
  private static final long FIELD_LIFETIME_SECS = 2;
  
  private final DisruptorFieldFactory factory;
  private final Set<GameUpdateLogic> gameUpdateLogicSet;
  private final DisruptorField disruptorField;
  private final Set<Blocker> blockerSet;
  
  private final long creationTimeInTicks;
  
  public DisruptorFieldGameUpdateLogic(
      DisruptorFieldFactory factory,
      Set<GameUpdateLogic> gameUpdateLogicSet, 
      DisruptorField disruptorField,
      Set<Blocker> blockerSet) {
    this.factory = factory;
    this.gameUpdateLogicSet = gameUpdateLogicSet;
    this.disruptorField = disruptorField;
    this.blockerSet = blockerSet;
    creationTimeInTicks = Timer.getTimer().getTime();
  }
  
  public void update(float timePerFrame) {
    long timeSinceCreation = (Timer.getTimer().getTime() - creationTimeInTicks) 
        / Timer.getTimer().getResolution();
    if (timeSinceCreation >= FIELD_LIFETIME_SECS) {
      factory.removeDisruptorField(disruptorField, this);
    }
  }
}
